/*潜在客户*/
Ext.define('App.crm.potentialCustomersList', {
    extend      : 'Ext.panel.Panel',
    alias       : 'widget.potentialCustomersList',
    layout:'fit',
    autoScroll:true,
    autoHeight:true,
    initComponent : function() {
    	var grid,  searchFlds;
    		searchFlds = new Ext.util.MixedCollection();
    		
        var	toolbar = new Ext.Toolbar({
            enableOverflow : true,
            items : [ {
                text : "新增",
                iconCls : 'addIcon',
                handler : function() {
                    var  potentialCustomersForm = Ext.create('App.crm.potentialCustomersForm');
                    potentialCustomersForm.show();
                    potentialCustomersForm.setTitle('新增');

                }
            }, '-', {
                text : "编辑",
                iconCls : 'editIcon',
                handler : function() {
                    var sm = Ext.getCmp('potentialCustomersGrid').getSelectionModel();
                    var records = sm.getSelection();
                    if (records.length <= 0) {
                        Ext.Msg.alert('错误', "未选中记录，不能修改！");
                        return;
                    }
                    var  potentialCustomersForm = Ext.create('App.crm.potentialCustomersForm');
                    potentialCustomersForm.show();
                    potentialCustomersForm.setTitle('编辑');
                    var data = records[0].raw;
                 var getForm=    potentialCustomersForm.down('form').getForm();
                    getForm.loadRecord(records[0]);
                    getForm.findField("state").setValue(data.state && data.state.toString());
                    getForm.findField("source").setValue(data.source && data.source.toString());
                    getForm.findField("industry").setValue(data.industry && data.industry.toString());
                }
            }, '-', {
                text : "删除",
                iconCls : 'deleteIcon',
                handler : function() {
                    Ext.getCmp('potentialCustomersGrid').deleteRecord();
                }
            }, "->",  , {
                text: "搜索",
                iconCls : 'searchIcon',
                handler: function () {
                    grid.load();
                }
            } ]
        });
        grid =	Ext.create('gridView',{
            remoteSort : true,
            forceFit: true,
            gridId :  'potentialCustomersGrid',
            checkboxSelectionModel:true,
            searchFlds : searchFlds,
            dataAutoLoad : false,
            entityClassName : 'com.rover.crm.entity.PotentialCustomers',
            queryUrl : 'potentialCustomersController/query.action',
            deleteUrl : 'potentialCustomersController/delete.action',
            recordPk : [ "id" ],
            tbar:toolbar,
            expander:{text:'操作',
                menuDisabled: true,
                sortable: false,
                align:'center',
                xtype: 'actioncolumn',
                width: 60,
                items: [{ icon   :'../images/smallIcon/settings.png', id: 'upArraw',    tooltip: '操作',
                    handler: function(grid, rowIndex, colIndex) {   //rowIndex，colIndex均从0开始
                        var rec = grid.getStore().getAt(rowIndex);
                        grid.currentRowIndex = rowIndex;
                        var url="crm/potentialCustomersView.jsp?potentialCustomersId="+rec.raw.id;
                        mainFrame("ht"+rec.raw.id,"合同："+rec.raw.name+"：查看",url,null,0);

                    } }]}
        });
        Ext.apply(this, {items:[grid]});
        grid.load();
        this.callParent(arguments);
    } , destroy: function () {
        Ext.getCmp('potentialCustomersList').destroy();
       this.destroy();
    }
});